package org.example.result;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;
@Data
public class R {

    private boolean success;
    private Integer code;

    private String message;

    private Map<String,Object> data = new HashMap<>();

    private R()       {   }


    public static R ok(){
        R r = new R();
        r.setSuccess(true);
        r.setCode(ResultCode.SUCCESS.getCode());
        r.setMessage("成功");
        return r;
    }

    public static R error() {
        R r = new R();
        r.setSuccess(false);
        r.setCode(ResultCode.ERROR.getCode());
        r.setMessage("失败");
        return r;
    }

    public R setSuccess(boolean success) {
        this.success = success;
        return this;
    }

    public R setCode(Integer code) {
        this.code = code;return this;
    }

    public R setMessage(String message) {
        this.message = message;return this;
    }

    public R setData(Map<String, Object> data) {
        this.data = data;return this;
    }
}
